package cn.gdrj.est.service.impl;

import cn.gdrj.est.dao.BrandDao;
import cn.gdrj.est.dto.BrandDTO;
import cn.gdrj.est.entity.Brand;
import cn.gdrj.est.service.BrandService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 商品品牌业务组件
 *
 * @author jun
 * @date 2021/11/8
 */
@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private BrandDao brandDao;

    // id in ()
    @Override
    public List<BrandDTO> listByIdsAndStatus(List<Long> ids, Integer status) {
        if(ObjectUtils.isEmpty(ids)){
            return new ArrayList<BrandDTO>();
        }

        List<Brand> brands = brandDao.listByIdsAndStatus(ids, status);
        List<BrandDTO> brandDTOS = new ArrayList<>();
        for (Brand brand : brands) {
            BrandDTO dto = new BrandDTO();
            BeanUtils.copyProperties(brand,dto);
            brandDTOS.add(dto);
        }
        return brandDTOS;
    }
}
